package dgut.party.business.dto.vo;

import dgut.party.business.entity.base.Menu;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@ToString
@SuperBuilder
public class MenuTree {

  public MenuTree(Menu rootMenu) {
    this.id = rootMenu.getId();
    this.icon = rootMenu.getIcon();
    this.name = rootMenu.getName();
    this.url = rootMenu.getAuth().getUrl();
    this.subMenus = rootMenu.getSubMenus().stream()
      .map(MenuTree::new)
      .sorted((pre, next) -> Long.valueOf(pre.getId() - next.getId()).intValue())
      .collect(Collectors.toList());
  }

  Long id;
  String icon;
  String name;
  String url;
  List<MenuTree> subMenus;
}
